package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatis.service.impl.CrudServiceImpl;
import com.example.dao.RawMaterialsConfigDao;
import com.example.dto.RawMaterialsConfigDTO;
import com.example.entity.RawMaterialsConfigEntity;
import com.example.service.RawMaterialsConfigService;
import com.example.utils.ConvertUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 原材料配置表
 *
 * @author yyyyjinying 1020066395@qq.com
 * @since 1.0-SNAPSHOT 2025-04-29
 */
@Service
public class RawMaterialsConfigServiceImpl extends CrudServiceImpl<RawMaterialsConfigDao, RawMaterialsConfigEntity, RawMaterialsConfigDTO> implements RawMaterialsConfigService {

    @Override
    public QueryWrapper<RawMaterialsConfigEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<RawMaterialsConfigEntity> wrapper = new QueryWrapper<>();


        return wrapper;
    }

    @Override
    public void save(RawMaterialsConfigDTO dto) {
        RawMaterialsConfigEntity entity = ConvertUtils.sourceToTarget(dto, RawMaterialsConfigEntity.class);
        entity.setConfigId(snowflake.nextId()); // 主键id可能有错误
        baseDao.insert(entity);
    }

    @Override
    public List<RawMaterialsConfigDTO> query(Long dishId) {
        List<RawMaterialsConfigEntity> query = baseDao.query(dishId);
        return ConvertUtils.sourceToTarget(query, RawMaterialsConfigDTO.class);
    }

    @Override
    public void deleteMaterials(List<Long> configIds, Long dishId) {
        baseDao.deleteMaterials(configIds, dishId);
    }

}